<template>
  <div class="page-style">
    <button-box @downloadFun="downloadFun" @reloadData="reloadData" @searchFun="searchFun" />
    <tab-list :table-data="warehouseInfoList" @reloadData="reloadData" />
    <pagination :total="total" :page="page" @pagination="handleChange" />
  </div>
</template>

<script>
import pagination from '@/components/Pagination'
import buttonBox from './components/warehouse-info/warehouse-info-button'
import tabList from './components/warehouse-info/warehouse-info-tab'
import { getWarehouseInfo } from '@/api/wms'
export default {
  components: {
    pagination,
    buttonBox,
    tabList
  },
  data() {
    return {
      msg: '仓库资料',
      total: 0,
      page: 1,
      warehouseInfoList: [],
      limit: 10,
      place: '',
      company: '',
      address: '',
      warehouse_name: ''
    }
  },
  created() {
    this.getwarehouseInfo()
  },
  methods: {
    // 新增仓库信息
    // handleAdd() {
    //   console.log('添加')
    // },
    // 导出Excel
    downloadFun() {
      const data = []
      const list = this.warehouseInfoList
      for (const i in list) {
        const arr = []
        arr.push(list[i].warehouse_name, list[i].company, list[i].desc, list[i].address, list[i].place)
        data.push(arr)
      }
      import('@/vendor/Export2Excel').then(excel => {
        excel.export_json_to_excel({
          header: ['仓库编号', '公司', '名称描述', '地址', '场所'],
          filename: '仓库资料',
          autoWidth: true,
          data: data
        })
      })
    },
    // pagination的size或page发生变化时触发
    handleChange(val) {
      this.page = val.page
      this.limit = val.limit
      this.getwarehouseInfo()
    },
    // 获取仓库数据
    getwarehouseInfo() {
      const data = {
        p: this.page,
        num: this.limit,
        place: this.place,
        company: this.company,
        address: this.address,
        warehouse_name: this.warehouse_name
      }
      getWarehouseInfo(data).then(res => {
        this.warehouseInfoList = res.list
        this.total = Number(res.count)
      })
    },
    // 重新加载数据
    reloadData() {
      this.getwarehouseInfo()
    },
    // 搜索
    searchFun(val) {
      // console.log(val)
      this.place = val.place
      this.company = val.company
      this.address = val.address
      this.warehouse_name = val.warehouse_name
      this.getwarehouseInfo()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
